﻿@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Web.Core;

@model Apps.Models.Sys.SysUserModel


@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";

    List<PermModel> perm = ViewBag.perm;
    if (perm == null)
    {
        perm = new List<PermModel>();
    }

}
<script src="@Url.Content("~/Scripts/jquery.easyui.plus.js")" type="text/javascript"></script>
<div id="modalwindow" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false" ></div>

<div class="mvctool">
    <input id="txtQuery" type="text" class="searchText" />
    @Html.ToolButton("btnQuery", "icon-search", "查询", true)
    @Html.ToolButton("btnCreate", "icon-add", "新增", true,perm,"Create")
    @Html.ToolButton("btnEdit", "icon-edit", "编辑", true,perm,"Edit")
    @Html.ToolButton("btnDetails", "icon-details", "详细", true,perm,"Details")
    @Html.ToolButton("btnDelete", "icon-remove", "删除", true,perm,"Delete")
    @Html.ToolButton("btnAllot", "icon-share", "分配角色", true, perm, "Allot")
</div>
<table id="List"></table>


<script type="text/javascript">
    $(function () {
        $('#List').datagrid({
            url: '@Url.Action("GetList")',
            width: $(window).width() - 10,
            method: 'post',
            height: $(window).height() - 35,
            fitColumns: true,
            sortName: 'CreateTime',
            sortOrder: 'desc',
            idField: 'Id',
            pageSize: 10,
            pageList: [10, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            //rownumbers: true,//行号
            columns: [[
                { field: 'Id', title: '', width: 80,hidden:true },
                { field: 'UserName', title: '用户名', width: 80, sortable: true },
                { field: 'Password', title: '', width: 80, sortable: true, hidden: true },
                { field: 'TrueName', title: '真实姓名', width: 80,sortable:true },
                { field: 'Card', title: '', width: 80, sortable: true, hidden: true },
                { field: 'MobileNumber', title: '身份证', width: 80, sortable: true, hidden: true },
                { field: 'PhoneNumber', title: '手机号码', width: 80,sortable:true },
                { field: 'QQ', title: '', width: 80, sortable: true, hidden: true},
                { field: 'EmailAddress', title: '', width: 80, sortable: true, hidden: true },
                { field: 'OtherContact', title: '', width: 80, sortable: true, hidden: true},
                { field: 'Province', title: '', width: 80, sortable: true, hidden: true},
                { field: 'City', title: '', width: 80, sortable: true, hidden: true },
                { field: 'Village', title: '', width: 80, sortable: true, hidden: true },
                { field: 'Address', title: '', width: 80, sortable: true, hidden: true },
                {
                    field: 'State', title: '是否启用', width: 80, sortable: true, formatter: function (value) {
                        if (value) {
                            return "是";
                        } else {
                            return "否";
                        }
                    }
                },
                { field: 'CreateTime', title: '创建时间', width: 80,sortable:true },
                { field: 'CreatePerson', title: '创建人', width: 80,sortable:true },
                { field: 'Sex', title: '', width: 80, sortable: true, hidden: true},
                { field: 'Birthday', title: '', width: 80, sortable: true, hidden: true},
                { field: 'JoinDate', title: '', width: 80, sortable: true, hidden: true},
                { field: 'Marital', title: '婚姻', width: 80, sortable: true, hidden: true },
                { field: 'Political', title: '党派', width: 80, sortable: true, hidden: true },
                { field: 'Nationality', title: '民族', width: 80, sortable: true, hidden: true },
                { field: 'Native', title: '籍贯', width: 80, sortable: true, hidden: true},
                { field: 'School', title: '毕业学校', width: 80, sortable: true, hidden: true},
                { field: 'Professional', title: '就读专业', width: 80, sortable: true, hidden: true },
                { field: 'Degree', title: '学历', width: 80, sortable: true, hidden: true },
                { field: 'DepId', title: '部门', width: 80, sortable: true, hidden: true },
                { field: 'PosId', title: '职位', width: 80, sortable: true, hidden: true},
                { field: 'Expertise', title: '个人简介', width: 80, sortable: true, hidden: true },
                { field: 'JobState', title: '在职状况', width: 80, sortable: true, hidden: true},
                { field: 'Photo', title: '照片', width: 80, sortable: true, hidden: true },
                { field: 'Attach', title: '附件', width: 80, sortable: true, hidden: true },
                {
                    field: 'Roles', title: '拥有角色', width: 80, sortable: true, formatter: function (value) {
                        var str = ""
                        for (var i = 0; i < value.length; i++) {
                            str += "[" + value[i] + "]";
                        }
                        return str;
                    }
                }
            ]]
        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
            $("#List").datagrid('load');
        else
            $("#List").datagrid('reload');
    }
    function frameReturnByMes(mes) {
        $.messageBox5s('提示', mes);
    }
    $(function () {
        $("#btnCreate").click(function () {
            $("#modalwindow").html("<iframe width='100%' height='98%' scrolling='yes' frameborder='0' src='/SysUser/Create'></iframe>");
            $("#modalwindow").window({ title: '新增', width: 700, height: 400, iconCls: 'icon-add' }).window('open');
        });
        $("#btnEdit").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='99%' scrolling='yes'  frameborder='0' src='/SysUser/Edit?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '编辑', width: 700, height: 430, iconCls: 'icon-edit' }).window('open');
            } else { $.messageBox5s('提示', '@Suggestion.PlaseChooseToOperatingRecords'); }
        });
        $("#btnDetails").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='98%' scrolling='yes' frameborder='0' src='/SysUser/Details?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '详细', width: 500, height: 300, iconCls: 'icon-details' }).window('open');
            } else { $.messageBox5s('提示', '@Suggestion.PlaseChooseToOperatingRecords'); }
	        });
        $("#btnQuery").click(function () {
            var queryStr = $("#txtQuery").val();
            if (queryStr == null) {
                queryStr = "%";
            }
            $('#List').datagrid({
                url: '@Url.Action("GetList")?queryStr=' + encodeURI(queryStr)
            });

        });
        $("#btnDelete").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $.messager.confirm('提示', '@Suggestion.YouWantToDeleteTheSelectedRecords', function (r) {
	                    if (r) {
	                        $.post("@Url.Action("Delete")?id=" + row.Id, function (data) {
                                if (data.tag == 1) {
                                    $("#List").datagrid('load');
                                    $.messageBox5s('提示', data.message);
                                } else {
                                    $.messageBox5s('提示', data.message);
                                }
	                        }, "json");

	                    }
	                });
	            } else { $.messageBox5s('提示', '@Suggestion.PlaseChooseToOperatingRecords'); }
        });
        $("#btnAllot").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='98%' scrolling='no' frameborder='0' src='/SysUser/Allot?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '详细', width: 500, height: 300, iconCls: 'icon-details' }).window('open');
            }
        });
    });
</script>
